package main;

import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.image.BufferStrategy;

import javax.swing.JFrame;

public class VirtualRoom {

	private static JFrame myFrame;
	private BufferStrategy strategy = null;
	public static final int width = 800;
	public static final int height = 600;
	public static Graphics2D graphics = null;
	public VirtualRoom( )
	{
		myFrame = new JFrame( "Virtual Room" );
		myFrame.setSize( new Dimension( (int)( width ) , (int)( height ) ) );
		myFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

		Toolkit kit = myFrame.getToolkit( );
		GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
		GraphicsDevice[] gs = ge.getScreenDevices();
		Insets in = kit.getScreenInsets(gs[0].getDefaultConfiguration());

		Dimension d = kit.getScreenSize();
		int max_width = (d.width - in.left - in.right);
		int max_height = (d.height - in.top - in.bottom);
		myFrame.setLocation( (int) ( max_width - myFrame.getWidth( ) ) >> 1 , ( int ) ( max_height - myFrame.getHeight( ) ) >> 1 );
		myFrame.setVisible( true );

		myFrame.createBufferStrategy( 2 );
		strategy = myFrame.getBufferStrategy( );

		new RunThread( );
	}

	public static JFrame getInstance( )
	{
		return myFrame;
	}

	public void update( )
	{
		strategy.getDrawGraphics( ).translate( 0 , 23 );
		graphics = (Graphics2D)strategy.getDrawGraphics( );
		strategy.show( );
	}

	class RunThread extends Thread
	{
		public RunThread( )
		{
			super( "Virtual Room Thread" );
			start( );
		}

		public void run( )
		{
			for( ; ; )
			{
				update( );
				try{ Thread.sleep( 10 ); } catch( Exception e ){ }
			}
		}
	}
}
